// Copyright 2018 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:startup_namer/app_store_item.dart';
import 'package:startup_namer/startup_namer.dart';
import 'package:startup_namer/update_item_model.dart';

import 'data_share.dart';
import 'methon_channel_sample.dart';

/// 主入口
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Learning',
        theme: ThemeData(primaryColor: Colors.black),
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Flutter Learning'),
          ),
          body: DemoListWidget(),
        ));
  }
}

/// Demo 列表
class DemoListWidget extends StatefulWidget {
  const DemoListWidget({Key? key}) : super(key: key);

  @override
  _DemoListWidgetState createState() => _DemoListWidgetState();
}

class _DemoListWidgetState extends State<DemoListWidget> {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        GestureDetector(
          child: _generateText("第一个 Flutter App"),
          onTap: _startupNamer,
        ),
        GestureDetector(
          child: _generateText("组装 Widget Demo"),
          onTap: _startAppStoreItemDemo,
        ),
        GestureDetector(
          child: _generateText("数据共享 Demo"),
          onTap: _startShareData,
        ),
        GestureDetector(
          child: _generateText("方法渠道 Demo"),
          onTap: _startChannelSample,
        ),
      ],
    );
  }

  Widget _generateText(String text) {
    return Column(
      children: [
        Container(
          child: Text(
            text,
            style: TextStyle(
              fontSize: 20,
              color: Colors.white,
            ),
            textAlign: TextAlign.left,
          ),
          padding: const EdgeInsets.fromLTRB(10, 15, 0, 15),
          color: Colors.black54,
          alignment: Alignment.centerLeft,
        ),
        const Divider(
          height: 1,
        )
      ],
    );
  }

  void _startupNamer() {
    Navigator.of(context).push(
      new MaterialPageRoute<void>(builder: (BuildContext context) {
        return RandomWords();
      }),
    );
  }

  void _startAppStoreItemDemo() {
    Navigator.of(context).push(
      new MaterialPageRoute<void>(builder: (BuildContext context) {
        return AppStoreItem(
            UpdateItemModel(
                appSize: '10M',
                appVersion: '1.0.0',
                appDate: '2021-08-02',
                appIcon: 'resources/images/ic_launcher.png',
                appDescription: '这是一个 Flutter 应用的描述这是一个 Flutter '
                    '应用的描述这是一个 Flutter 应用的描述这是一个 Flutter 应用的描述',
                appName: '红袖'),
            () {});
      }),
    );
  }

  void _startShareData() {
    Navigator.of(context).push(
      new MaterialPageRoute<void>(builder: (BuildContext context) {
        return InheritedWidgetTestRoute();
      }),
    );
  }
  void _startChannelSample() {
    Navigator.of(context).push(
      new MaterialPageRoute<void>(builder: (BuildContext context) {
        return ChannelSampleHomePage();
      }),
    );
  }
}
